// 验证

// 起点验证
export function verify_o(propsData) {
  let pass = true;
  let message = [];
  const { initiator, initiatePos, initiateRole } = propsData;
  if (!initiator.length && !initiatePos.length && !initiateRole.length) {
    //   若人员、角色、岗位都为空。则不能通过
    pass = false;
    message.push("请设置发起人员");
  }
  return {
    pass,
    message,
  };
}

// 审批验证
export function verify_e(propsData) {
  let pass = true;
  let message = [];
  const { assigneeType, approvers, approverPos, approverRole } = propsData;

  if (
    assigneeType === 1 &&
    !approvers.length &&
    !approverPos.length &&
    !approverRole.length
  ) {
    //   若人员、角色、岗位都为空。则不能通过
    pass = false;
    message.push("请设置审批人员");
  }
  return {
    pass,
    message,
  };
}

// 子流程验证
export function verify_s(propsData) {
  let pass = true;
  let message = [];

  const { initiateType, initiator, initiatePos, initiateRole, flowId } =
    propsData;

  if (
    initiateType === 1 &&
    !initiator.length &&
    !initiatePos.length &&
    !initiateRole.length
  ) {
    pass = false;
    message.push("请设置发起人员");
  }

  if (!flowId) {
    pass = false;
    message.push("请设置子流程表单");
  }

  return {
    pass,
    message,
  };
}

//条件验证
export function verify_c(propsData) {
  let pass = true;
  let message = [];

  const { conditions } = propsData;
  if (conditions && conditions.length > 0) {
    for (let v of conditions) {
      for (let key in v) {
        if (!v[key]) {
          pass = false;
          if (key === "fieldName" || key === "field") {
            message.push("请设置字段名");
          }
          if (key === "symbolName" || key === "symbol") {
            message.push("请设置条件");
          }
          if (key === "filedValue") {
            message.push("请设置数据值");
          }
          if (key === "logicName" || key === "logic") {
            message.push("请设置后续逻辑");
          }
        }
      }
    }
  }

  return {
    pass,
    message,
  };
}

// 定时器验证
export function verify_t(propsData) {
  let pass = true;
  let message = [];

  return {
    pass,
    message,
  };
}

const actionGroup = {
  verify_o,
  verify_e,
  verify_s,
  verify_c,
  verify_t,
};

export default function (type, data) {
  let key = "verify_" + type.toLowerCase();
  return actionGroup[key] && actionGroup[key](data);
}
